package autumn.hot100;

import java.util.LinkedList;

public class Solution739 {
    public int[] dailyTemperatures(int[] temperatures) {
        LinkedList<int[]> stack = new LinkedList<>();
        int n = temperatures.length;
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            while (!stack.isEmpty() && stack.getLast()[0] < temperatures[i]) {
                int[] curs = stack.removeLast();
                res[curs[1]] = i - curs[1];
            }
            stack.add(new int[]{temperatures[i], i});
        }
        return res;
    }
}
